// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexManagement;

public sealed partial class MappingLimitSettingsTotalFields
{
	/// <summary>
	/// <para>
	/// This setting determines what happens when a dynamically mapped field would exceed the total fields limit. When set
	/// to false (the default), the index request of the document that tries to add a dynamic field to the mapping will fail
	/// with the message Limit of total fields [X] has been exceeded. When set to true, the index request will not fail.
	/// Instead, fields that would exceed the limit are not added to the mapping, similar to dynamic: false.
	/// The fields that were not added to the mapping will be added to the _ignored field.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("ignore_dynamic_beyond_limit")]
	public bool? IgnoreDynamicBeyondLimit { get; set; }

	/// <summary>
	/// <para>
	/// The maximum number of fields in an index. Field and object mappings, as well as field aliases count towards this limit.
	/// The limit is in place to prevent mappings and searches from becoming too large. Higher values can lead to performance
	/// degradations and memory issues, especially in clusters with a high load or few resources.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("limit")]
	public long? Limit { get; set; }
}

public sealed partial class MappingLimitSettingsTotalFieldsDescriptor : SerializableDescriptor<MappingLimitSettingsTotalFieldsDescriptor>
{
	internal MappingLimitSettingsTotalFieldsDescriptor(Action<MappingLimitSettingsTotalFieldsDescriptor> configure) => configure.Invoke(this);

	public MappingLimitSettingsTotalFieldsDescriptor() : base()
	{
	}

	private bool? IgnoreDynamicBeyondLimitValue { get; set; }
	private long? LimitValue { get; set; }

	/// <summary>
	/// <para>
	/// This setting determines what happens when a dynamically mapped field would exceed the total fields limit. When set
	/// to false (the default), the index request of the document that tries to add a dynamic field to the mapping will fail
	/// with the message Limit of total fields [X] has been exceeded. When set to true, the index request will not fail.
	/// Instead, fields that would exceed the limit are not added to the mapping, similar to dynamic: false.
	/// The fields that were not added to the mapping will be added to the _ignored field.
	/// </para>
	/// </summary>
	public MappingLimitSettingsTotalFieldsDescriptor IgnoreDynamicBeyondLimit(bool? ignoreDynamicBeyondLimit = true)
	{
		IgnoreDynamicBeyondLimitValue = ignoreDynamicBeyondLimit;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The maximum number of fields in an index. Field and object mappings, as well as field aliases count towards this limit.
	/// The limit is in place to prevent mappings and searches from becoming too large. Higher values can lead to performance
	/// degradations and memory issues, especially in clusters with a high load or few resources.
	/// </para>
	/// </summary>
	public MappingLimitSettingsTotalFieldsDescriptor Limit(long? limit)
	{
		LimitValue = limit;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (IgnoreDynamicBeyondLimitValue.HasValue)
		{
			writer.WritePropertyName("ignore_dynamic_beyond_limit");
			writer.WriteBooleanValue(IgnoreDynamicBeyondLimitValue.Value);
		}

		if (LimitValue.HasValue)
		{
			writer.WritePropertyName("limit");
			writer.WriteNumberValue(LimitValue.Value);
		}

		writer.WriteEndObject();
	}
}